<?php
$whmcs_path = "whmcs";
$per_page = 2;
$root_adminroleid = 1;
mysql_set_charset('utf8');

if (!isset($_SESSION["adminid"]) || !defined('ROOTDIR') || (!mysql_num_rows(mysql_query("SELECT permid FROM tbladmins JOIN tbladminperms ON tbladmins.roleid = tbladminperms.roleid WHERE permid=46 AND tbladmins.id=". intval($_SESSION["adminid"])))))
{
	exit("Access Denied");
}
?>
<style type="text/css">
.ext-el-mask{z-index:20000;position:fixed;top:0;left:0;-moz-opacity:0.5;opacity:.50;filter:alpha(opacity=50);background-color:#CCC;width:100%;height:100%;zoom:1;}
.ext-el-mask-msg{z-index:20001;position:absolute;top:0;left:0;border:1px solid #6593cf;background:#c3daf9 url(images/tb-blue.gif) repeat-x 0 -16px;padding:2px;}
.ext-el-mask-msg div{padding:5px 10px 5px 10px;background:#eee;border:1px solid #a3bad9;color:#333;font:normal 12px tahoma,arial,helvetica,sans-serif;cursor:wait;}
.x-mask-loading div{padding:5px 10px 5px 25px;background:#eee url(images/loading.gif) no-repeat 5px 5px;line-height:16px;}
#loading-msg{position:fixed;top:45%!important;left:43%!important;z-index:20001!important;}
.tabspacer{border-bottom:1px solid #cccccc;}
.tab{padding-top:2px;padding-bottom:2px;padding-left:10px;padding-right:10px;background-color:#efefef;border:1px solid #cccccc;cursor: pointer;cursor: hand;}
.tab a{text-decoration: none;color: #000000;}
.tabselected{padding-top:2px;padding-bottom:2px;padding-left:10px;padding-right:10px;background-color:#ffffff;border-top:1px solid #cccccc;border-left:1px solid #cccccc;border-right:1px solid #cccccc;border-bottom:0px;font-weight: bold;cursor: pointer;cursor: hand;}
.tabbox{padding:10px;border-left:1px solid #cccccc;border-right:1px solid #cccccc;border-bottom:1px solid #cccccc;}
#infobox{background-image:url('../images/warning.gif');background-repeat:no-repeat;	background-position:5px;margin: 10px 5px 10px 5px;padding: 5px 5px 5px 45px;	background-color:#FCF9D2;border: 1px solid #F9D43E;}
</style>
<?php

if ($_REQUEST["op"]=="add_cat")
{ 
  if (mysql_query("INSERT INTO mod_internalkb (id, parentid, type, titlevi, titleen, contentvi, contenten, owner, lastupdate, updatedby, public, active, editing) VALUES (NULL, '".intval($_REQUEST["parentid"])."', 'cat', '".mysql_real_escape_string($_REQUEST["titlevi"])."', '".mysql_real_escape_string($_REQUEST["titleen"])."', '', '', '0', NOW(), '0', '".intval($_REQUEST["public"])."', '1', '0'); "))	
	{
		$id = mysql_insert_id();
    mysql_query("INSERT INTO mod_tracker (id, type, uid, tid) VALUES (NULL, 'ikb_racl', '".$root_adminroleid."', '".$id."');");
    mysql_query("INSERT INTO mod_tracker (id, type, uid, tid) VALUES (NULL, 'ikb_racl', '".$root_adminroleid."', '".$id."');");
		$result = mysql_query("SELECT * FROM tbladminroles WHERE 1;");			
		while ($adminr = mysql_fetch_assoc($result))
		{			
			if (isset($_REQUEST["racl_".$adminr["id"]]))
			{			
				mysql_query("INSERT INTO mod_tracker (id, type, uid, tid) VALUES (NULL, 'ikb_racl', '".$adminr["id"]."', '".$id."');");
			}
			if (isset($_REQUEST["wacl_".$adminr["id"]]))
			{
				mysql_query("INSERT INTO mod_tracker (id, type, uid, tid) VALUES (NULL, 'ikb_wacl', '".$adminr["id"]."', '".$id."');");
			}
		}	
		header("Location: ".$modulelink."&t=2");
	}
	else
		exit("<div id=infobox>".mysql_error()."</div>");
}
?>

<div id="loading-mask" class="ext-el-mask" style="display: none;"></div>
<div id="loading-msg" class="ext-el-mask-msg x-mask-loading" style="display: none;">
  <div>Processing...</div>
</div>
<script>
 $(".tabboxx").css("display","none");
var selectedTab;
$(".tab").click(function(){
    var elid = $(this).attr("id");
    $(".tab").removeClass("tabselected");
    $("#"+elid).addClass("tabselected");
    $(".tabboxx").slideUp();
    if (elid != selectedTab) {
        selectedTab = elid;
        $("#"+elid+"boxx").slideDown();
    } else {
        selectedTab = null;
        $(".tab").removeClass("tabselected");
    }
    $("#tab").val(elid.substr(3));
});
</script>
<?php
function print_editor()
{
  echo '<script language="javascript" type="text/javascript" src="editor/tiny_mce.js"></script>
			<script language="javascript" type="text/javascript">
      tinyMCE.init({
	mode : "textareas",
	theme : "advanced",
	relative_urls : true,
	plugins : "paste,noneditable,	table,save,advhr,advimage,advlink,iespell,insertdatetime,preview,zoom,flash,searchreplace,print,contextmenu",
	theme_advanced_buttons1_add_before : "save,separator",
	theme_advanced_buttons1_add : "fontselect,fontsizeselect",
	theme_advanced_buttons2_add : "separator,insertdate,inserttime,preview,zoom,separator,forecolor,backcolor",
	theme_advanced_buttons2_add_before: "cut,copy,paste,separator,search,replace,separator",
	theme_advanced_buttons3_add_before : "tablecontrols,separator",
	theme_advanced_buttons3_add : "iespell,flash,advhr,separator,print",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_path_location : "bottom",
	theme_advanced_resizing : true,
	apply_source_formatting : true,
	theme_advanced_resize_horizontal : true,
	entities : "160,nbsp",
	force_br_newlines : true,
	force_p_newlines : false,	
	plugin_insertdate_dateFormat : "%Y-%m-%d",
	plugin_insertdate_timeFormat : "%H:%M:%S",
	extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
	file_browser_callback : "ajaxfilemanager"
});
function toggleEditor(id) {
	var elm = document.getElementById(id);
	if (tinyMCE.getInstanceById(id) == null)
		tinyMCE.execCommand(\'mceAddControl\', false, id);
	else
		tinyMCE.execCommand(\'mceRemoveControl\', false, id);
};
function ajaxfilemanager(field_name, url, type, win) {
	var ajaxfilemanagerurl = "../../../editor/plugins/ajaxfilemanager/ajaxfilemanager.php";
	switch (type) {
		case "image":
			break;
		case "media":
			break;
		case "flash": 
			break;
		case "file":
			break;
		default:
			return false;
	}
	var fileBrowserWindow = new Array();
	fileBrowserWindow["file"] = ajaxfilemanagerurl;
	fileBrowserWindow["title"] = "Ajax File Manager";
	fileBrowserWindow["width"] = "782";
	fileBrowserWindow["height"] = "440";
	fileBrowserWindow["close_previous"] = "no";
	tinyMCE.openWindow(fileBrowserWindow, {
		window : win,
		input : field_name,
		resizable : "yes",
		inline : "yes",
		editor_id : tinyMCE.getWindowArg("editor_id")
	});
			
	return false;
}
</script>';
}

function get_admin_role($admin_id)
{
	$result = mysql_query("SELECT roleid FROM tbladmins WHERE (id='".intval($admin_id)."');");
  if (!$result)
    return -1;
	$r = mysql_fetch_assoc($result);
	return $r["roleid"];
}

function get_admin_name($admin_id)
{
	$result = mysql_query("SELECT username FROM tbladmins WHERE (id='".intval($admin_id)."');");
	$r = mysql_fetch_assoc($result);
	return $r["username"];
}

function preview($article, $num, $tail='&nbsp;...')
{
	$words = explode(" ", $article);
    $firstwords = array_slice($words, 0, $num);
    return implode(" ", $firstwords).$tail;
}

function view_entry($id)
{
	global $modulelink;

	$result = mysql_query("SELECT * FROM mod_kb WHERE (id='".intval($id)."');");
	
	if (mysql_error())
	{
		$read = 0;
	}
	else
	{
		$entry = mysql_fetch_assoc($result);	
		
		if ((get_admin_role($_SESSION["adminid"])==1) || ($_SESSION["adminid"]==$entry["owner"]))
		{
			$read = 1;
			$write = 1;
		}
		else
		{	
			if ($entry["public"]==1)
			{
				$read = 1;
			}
			else
			{	
				$read = 1;
			}
			$write = 1;
		}
	}

	if ($read)
	{		
		echo "<table width=100% cellspacing=0><tr>
		<td width=5 class='tabspacer'><img src='images/spacer.gif' width=5 height=1></td>
		<td id='tab0' class='tab' onClick='TabClick(0)' nowrap>".$entry["title"]."</td>
		<td width=2 class='tabspacer'><img src='images/spacer.gif' width=2 height=1></td>";
		
		if ($write)
		{
			echo "<td id='tab1' class='tab' onClick='TabClick(1)' nowrap>Edit</td>
			<td width=2 class='tabspacer'><img src='images/spacer.gif' width=2 height=1></td>";		
		}
		
		echo "<td id='tab".(1+$write)."' class='tab' onClick='TabClick(".(1+$write).")' nowrap>Search</td>
		<td width=2 class='tabspacer'><img src='images/spacer.gif' width=2 height=1></td>
		<td width=100% class='tabspacer'>&nbsp;</td></tr>
		<tr id='tabbox0'>
		<td colspan=".(6+2*$write)." class='tabbox'>".htmlspecialchars_decode($entry["article"])."<div style='border-top:1px solid #CCC;padding-top:5px;'>
			<table width=100% cellspacing=0 cellpadding=0><tr><td align='left' style='color:#CCC;'>Created by ".get_admin_name($entry["owner"])."</td><td align='right' style='color:#CCC;'>Last updated by ".get_admin_name($entry["updatedby"])." at ".$entry["lastupdate"]."</span></td></tr></table></div></td></tr>";
		
		if ($write)
		{
			echo "<tr id='tabbox1'><td colspan=8 class='tabbox'>";
			print_editor();
      echo "
			<form name='edit_entry_form' method='post' action='".$modulelink."'>
			<input type='hidden' name='op' value='edit_entry'/>
			<input type='hidden' name='id' value='".$id."'/>
			<table width=100% cellspacing=1 cellpadding=0 bgcolor=#8FBCE9><tr><td bgcolor=#ffffff>
				<table width=100% cellpadding=2>					
					<tr><td align='right'>Title: </td><td class='fieldarea'><input type='text' name='title' size=70 value=\"".$entry["title"]."\"></td></tr>";
			if (get_admin_role($_SESSION["adminid"])==1)
			{
				echo "<tr><td align='right'>Owner: </td><td class='fieldarea'>
					<select name='owner'>";		
				$admins = mysql_query("SELECT * FROM tbladmins WHERE 1;");	
				while ($admin = mysql_fetch_assoc($admins))
				{	
					echo "<option value='".$admin["id"]."'";
					if ($entry["owner"]==$admin["id"]) 
						echo " selected";
					echo ">".$admin["username"];
				}	
				echo "</select></td></tr>";
			}		
			echo "<tr><td align='right'>Active: </td><td class='fieldarea'><input type='radio' name='active' value=1 "; 
			if ($entry["active"]) 
			{
				echo "checked/> Yes <input type='radio' name='active' value=0 ";
			}
			else
			{
				echo "/> Yes <input type='radio' name='active' value=0 checked";
			}
			echo " /> No </td></tr>
			<tr><td align='right'>Public: </td><td class='fieldarea'><input type='radio' name='public' value=1 ";
			if ($entry["public"]) 
			{
				echo "checked/> Yes <input type='radio' name='public' value=0 ";
			}
			else
			{
				echo "/> Yes <input type='radio' name='public' value=0 checked";
			}
			echo "/> No </td></tr>
				</table>
				</td></tr>
			</table>
			<br/><textarea name='article' rows=18 style='width:100%'>".$entry["article"]."</textarea><br/>";		
			echo "<center><table cellspacing=1 cellpadding=3 bgcolor='#cccccc'>
				<tr bgcolor='#efefef' style='text-align:center;font-weight:bold'><td>Admin Roles</td><td width='50'>Read</td><td width='50'>Write</td></tr>";	
			$aresult = mysql_query("SELECT * FROM tbladminroles WHERE id>1;");	
			while ($admins = mysql_fetch_assoc($aresult))
			{
				echo "<tr bgcolor='#ffffff' style='text-align:center;'><td>".$admins["name"]."</td><td><input type='checkbox' name='racl_".$admins["id"]."' value='1'";
				if (mysql_num_rows(mysql_query("SELECT * FROM mod_tracker WHERE (type='ikb_racl' AND uid='".$admins["id"]."' AND tid='".intval($id)."');")))
					echo " checked";				
				echo "></td><td><input type='checkbox' name='wacl_".$admins["id"]."' value='1'";
				if (mysql_num_rows(mysql_query("SELECT * FROM mod_tracker WHERE (type='ikb_wacl' AND uid='".$admins["id"]."' AND tid='".intval($id)."');")))
					echo " checked";				
				echo "></td></tr>";
			}	
			echo "</table><br/>
			<input type='submit' value='Save changes' class='button'></center>
			</form>
			<div align='right'>
			<form method='post' action='".$modulelink."' onsubmit='return confirmDeleteEntry();'>
			<input type='hidden' name='op' value='delete_entry'>
			<input type='hidden' name='id' value='".$id."'>			
			<input type='submit' value='Delete' class='button'>
			</form></div>
			</td></tr>";					
		}
		echo "<tr id='tabbox".(1+$write)."'>
		<td colspan=".(6+2*$write)." class='tabbox'>";
		form_search();
		echo "</td></tr>
		</table>
		<script language='javascript'>var tabs = ".(2+$write)."; </script>
		<script language='javascript' src='javascript/tabs.js'></script>
		<script language='javascript'>TabClick(0);</script>
		<script language='javascript'>
		function confirmDeleteEntry() {
		return confirm('Are you sure you want to delete this article?')}
</script>";				
	}
	else
	{
		echo "<div id=infobox>You don't have read access to this article!</div>";
	}
}

function form_add_entry()
{
	global $modulelink;
	
}

function form_search()
{
	global $modulelink;
	echo "<form action=".$modulelink." method='POST'>
	<table width=100% cellspacing=1 cellpadding=0 bgcolor=#8FBCE9><tr><td bgcolor=#FFFFFF>
	<table width=100% cellspacing=5 cellpadding=0><tr><td width=100% valign=top>
		<table width=100% cellpadding=2 cellspacing=0>
		<tr><td align=right width=100>Keyword:</td>
		<td class='fieldarea' colspan=5><input type='text' name='s' size=100";
	if (isset($_REQUEST["s"])) 
		echo " value=\"".$_REQUEST["s"]."\"";
	echo "/></td></tr>
		<tr><td align=right width=100>Unread Only:</td>
		<td><input type='checkbox' name='unread' value='1'";
	if (isset($_REQUEST["unread"]))
		echo "checked";
	echo "	/>
		</td>
		<td align=right width=100>Search in:</td>
		<td><select name='in'>";
	if (isset($_REQUEST["in"]) && $_REQUEST["in"]==1)
		echo "<option value='0'>Any
			<option value='1' selected>Title
			<option value='2'>Content";	
	else if (isset($_REQUEST["in"]) && $_REQUEST["in"]==2)
		echo "<option value='0'>Any
			<option value='1'>Title
			<option value='2' selected>Content";	
	else	
		echo "<option value='0' selected>Any
			<option value='1'>Title
			<option value='2'>Content";
	echo "</select>
		</td><td align=right width=100>Status:</td>
		<td><select name='active'>";
	if (isset($_REQUEST["active"]) && $_REQUEST["active"]==0)
		echo "<option value='1'>Active
			<option value='0' selected>Inactive
			<option value='2'>Any";
	else if (isset($_REQUEST["active"]) && $_REQUEST["active"]==2)
		echo "<option value='1'>Active
			<option value='0'>Inactive
			<option value='2' selected>Any";
	else
		echo "<option value='1' selected>Active
			<option value='0'>Inactive
			<option value='2'>Any";			
	echo "</select>
		</td></tr><tr>
		<td align=right width=100>Public access:</td>
		<td><select name='public'>";
	if (isset($_REQUEST["public"]) && $_REQUEST["public"]==1)
		echo "<option value='2'>Any
			<option value='1' selected>Yes
			<option value='0'>No";
	else if (isset($_REQUEST["public"]) && $_REQUEST["public"]==0)	
		echo "<option value='2'>Any
			<option value='1'>Yes
			<option value='0' seleted>No";
	else
		echo "<option value='2' selected>Any
			<option value='1'>Yes
			<option value='0'>No";
	echo "</select>
		</td><td align=right width=100>Created by:</td>
		<td><select name='owner'>
			<option value='0'";
	if (!isset($_REQUEST["owner"])) 
		echo " selected";
	echo ">Anyone";
	$admins = mysql_query("SELECT * FROM tbladmins WHERE 1;");	
	while ($admin = mysql_fetch_assoc($admins))
	{	
		echo "<option value='".$admin["id"]."'";
		if (isset($_REQUEST["owner"]) && $_REQUEST["owner"]==$admin["id"]) 
			echo " selected";
		echo ">".$admin["username"];
	}	
	echo "	</select>
		</td>
		<td align=right width=100>Last updated by:</td>
		<td><select name='updatedby'>
			<option value='0'";
	if (!isset($_REQUEST["updatedby"]))			
		echo " selected";
	echo ">Anyone";
	mysql_data_seek($admins, 0);
	while ($admin = mysql_fetch_assoc($admins))
	{	
		echo "<option value='".$admin["id"]."'";
		if (isset($_REQUEST["updatedby"]) && $_REQUEST["updatedby"]==$admin["id"])
			echo " selected";
		echo ">".$admin["username"];
	}	
	echo "	</select>
	</td></tr></table>
	</td></tr></table>
	</td></tr></table>
	<img src='images/spacer.gif' height='5' width='1'><br/>
	<input type='hidden' name='op' value='search'>
	<div align='center'><input type='submit' value='Search' class='button'></div>
	</form>";
}



/* load the category list into an array */
$result = mysql_query("SELECT id, parentid, titlevi FROM mod_internalkb WHERE (type='cat') ORDER BY id ASC;");
$cats = array();
if (mysql_num_rows($result)>0)
{
  while ($row = mysql_fetch_assoc($result)) 
  {
    $tmpcats[$row["id"]] = $row;
  } 
  foreach($tmpcats as $cat)
  {
    $tmpid = $cat["parentid"];
    $sf = 5;
    $ps = $cat["id"];
    while (($tmpid > 0) && ($sf > 0))
    { 
      $ps = $tmpid.".".$ps;
      $tmpid = $tmpcats[$tmpid]["parentid"]; 
      $sf--;
    } 
    $cats[$ps] = $cat;
  }
  ksort($cats);
}



if (($_REQUEST["op"]=="view_entry") && isset($_REQUEST["id"]))
{
	view_entry($_REQUEST["id"]);
}
else if (!isset($_REQUEST["op"]))
{		
	echo "<table width=100% cellspacing=0><tr>
		<td width=5 class='tabspacer'><img src='images/spacer.gif' width=5 height=1></td>		
		<td id='tab0' class='tab' onClick='TabClick(0)' nowrap>Search</td>
		<td width=2 class='tabspacer'><img src='images/spacer.gif' width=2 height=1></td>	
		<td id='tab1' class='tab' onClick='TabClick(1)' nowrap>Add new entry</td>
		<td width=2 class='tabspacer'><img src='images/spacer.gif' width=2 height=1></td>			
    <td id='tab2' class='tab' onClick='TabClick(2)' nowrap>Manage Categories</td>
		<td width=2 class='tabspacer'><img src='images/spacer.gif' width=2 height=1></td>			
		<td width=100% class='tabspacer'>&nbsp;</td></tr>
		<tr id='tabbox0' style='display:none;'>		
		<td colspan=8 class='tabbox'>";
	form_search();	
	
  echo "</td></tr>
		<tr id='tabbox1' style='display:none;'>
		<td colspan=8 class='tabbox'>";
    
	//print_editor();
  
	echo "<form method='post' action='".$modulelink."'>
			<input type='hidden' name='op' value='add_entry'/>
			<input type='hidden' name='owner' value='".$_SESSION["adminid"]."'/>
			<table width=100% cellspacing=1 cellpadding=0 bgcolor=#8FBCE9><tr><td bgcolor=#ffffff>
				<table width=100% cellpadding=2>					
					<tr><td align='right'>Title: </td><td class='fieldarea'><input type='text' name='title' size=70></td></tr>          
					<tr><td align='right'>Active: </td><td class='fieldarea'><input type='radio' name='active' value=1 checked /> Yes <input type='radio' name='active' value=0 /> No</td></tr>
					<tr><td align='right'>Public: </td><td class='fieldarea'><input type='radio' name='public' value=1 /> Yes <input type='radio' name='public' value=0 checked /> No</td></tr>
				</table>
				</td></tr>
			</table>
			<br/><textarea name='article' rows=18 style='width:100%'></textarea>
			<br/><center><table cellspacing=1 cellpadding=3 bgcolor='#cccccc'>
				<tr bgcolor='#efefef' style='text-align:center;font-weight:bold'><td>Admin Roles</td><td width='50'>Read</td><td width='50'>Write</td></tr>";	
  $aresult = mysql_query("SELECT * FROM tbladminroles WHERE id>1;");	
	while ($admins = mysql_fetch_assoc($aresult))
	{
		echo "<tr bgcolor='#ffffff' style='text-align:center;'>
      <td>".$admins["name"]."</td>
			<td><input type='checkbox' name='racl_".$admins["id"]."' value='1'></td>
			<td><input type='checkbox' name='wacl_".$admins["id"]."' value='1'></td>
			</tr>";
	}	
	echo "</table><br/>
			<input type='submit' value='Save changes' class='button'></center>
			</form>";
      
	echo "</td></tr>			  
		<tr id='tabbox2' style='display:none;'>
		<td colspan=8 class='tabbox'>";
  
  if (get_admin_role($_SESSION["adminid"])!=$root_adminroleid)
  {
    echo "<div id='infobox'>You don't have permission to access this section!</div>";
  }
  else
  {  
  echo '<div id="tab5" class="tab"><a href="javascript:;">Add Category</a></div>';
    echo "<div id='tab5boxx' class='tabboxx'>
  <div id='tab_content'>
<form method='post' action='".$modulelink."'>
		<input type='hidden' name='op' value='add_cat'/>
    <table width=100% cellspacing=1 cellpadding=0 bgcolor=#8FBCE9><tr><td bgcolor=#ffffff>
				<table width=100% cellpadding=2>					
					<tr><td align='right'>Title (VI): </td><td class='fieldarea'><input type='text' name='titlevi' size=70> <i>(required)</i></td></tr>					
          <tr><td align='right'>Title (EN): </td><td class='fieldarea'><input type='text' name='titleen' size=70></td></tr>
					<tr><td align='right'>Parent Category: </td><td class='fieldarea'>
				";
    echo "<select name='parentid'><option value='0'>--- None ---";
    foreach ($cats as $key => $cat)
    {
      echo "<option value='".$cat["id"]."'>";
      for ($x=1;$x<count(explode(".",$key));$x++) { echo "-";}
      if (count(explode(".",$key))>1) echo " ";
      echo $cat["titlevi"];
    }
    echo "</select>
    </td></tr>
    <tr><td align='right'>Public: </td><td class='fieldarea'><input type='radio' name='public' value=1 /> Yes <input type='radio' name='public' value=0 checked /> No </td></tr>
    </table>
    <br/><center>
    <table cellspacing=1 cellpadding=3 bgcolor='#cccccc'>
    <tr bgcolor='#efefef' style='text-align:center;font-weight:bold'>
    <td>Admin Roles</td><td width='50'>Read</td><td width='50'>Write</td></tr>    
    <tr bgcolor='#ffffff' style='text-align:center;'>";
    mysql_data_seek($aresult,0);
    while ($admins = mysql_fetch_assoc($aresult))
    {
      echo "<tr bgcolor='#ffffff' style='text-align:center;'>
        <td>".$admins["name"]."</td>
        <td><input type='checkbox' name='racl_".$admins["id"]."' value='1'></td>
        <td><input type='checkbox' name='wacl_".$admins["id"]."' value='1'></td>
        </tr>";
    }	
    echo "</tr></table><br/>      
			<input type='submit' value='Add Category' class='button'></center>
      <br/>
				</td></tr>
			</table>
      </form></div></div>
      <br/>
      <b>Categories:</b>
      <br/>
      <table width=100%>";
      
    foreach ($cats as $key => $cat)
    {
      echo "<tr><td width=100%>";
      for ($x=1;$x<count(explode(".",$key));$x++) 
      { 
        echo "-- ";
      }
      echo "<a href='".$cat["id"]."'>";   
      echo $cat["titlevi"]."</a></td></tr>";
    }  
    echo "</table>";
  }
  
  echo "</td></tr>
		</table>
		<script language='javascript'>
    var tabs = 3;
    function TabClick(sel) 
    {
      for(i=0;i<tabs;i++) 
      {
        document.getElementById('tab'+i).className='tab';
        document.getElementById('tabbox'+i).style.display='none';
      }
      document.getElementById('tab'+sel).className='tabselected';
      document.getElementById('tabbox'+sel).style.display='';
    }
    </script>";
  if (isset($_REQUEST["t"]))
    echo "<script language='javascript'>TabClick(".intval($_REQUEST["t"]).");</script>";
  else
    echo "<script language='javascript'>TabClick(0);</script>";
}


?>
